package com.java.controller.api;


import com.java.config.result.Result;
import com.java.model.hosp.Hospital;
import com.java.model.user.Patient;
import com.java.model.vo.DepartmentVo;
import com.java.model.vo.HospitalQueryVo;
import com.java.model.vo.ScheduleOrderVo;
import com.java.service.DepartmentService;
import com.java.service.HospitalService;
import com.java.service.ScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@Api("医院设置")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HosApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    /**
     * 前台医院列表分页
     * @param pageNum
     * @param pageSize
     * @param hospitalQueryVo
     * @return
     */
    @ApiOperation("前台医院列表分页")
    @ApiModelProperty(value = "医院列表分页")
    @GetMapping("/getHospList/{pageNum}/{pageSize}")
    public Result getHosList(@PathVariable Integer pageNum,
                             @PathVariable Integer pageSize,
                             HospitalQueryVo hospitalQueryVo){

        Page result = hospitalService.selectPageList(pageNum,pageSize,hospitalQueryVo);
        return Result.ok(result);
    }

    /**
     * 根据医院名称模糊查询
     * @param hosname
     * @return
     */
    @ApiOperation("根据医院名称模糊查询")
    @GetMapping("getHospital/{hosname}")
    public Result getHospitalByHosname(@PathVariable String hosname){
        List<Hospital> result = hospitalService.getHospitalByhosname(hosname);
        return Result.ok(result);
    }

    //获取科室
    @ApiOperation("获取科室")
    @GetMapping("/department/{hoscode}")
    public Result getDepartmentList(@PathVariable String hoscode){
        //获取科室信息
        List<DepartmentVo> result =  departmentService.findByHoscode(hoscode);
        return Result.ok(result);
    }

    //获取医院详情
    @ApiOperation("获取医院详情")
    @GetMapping("/hospDetail/{hoscode}")
    public Result getHospitalDetail(@PathVariable String hoscode){
        //获取科室信息
        Map<String,Object> result = hospitalService.getHospitalByhoscode(hoscode);
        return Result.ok(result);
    }

    @Autowired
    private ScheduleService scheduleService;

    //获取可预约排班数据日期 进行分页
    @ApiOperation("获取可预约排班数据日期进行分页")
    @GetMapping("auth/getBookingScheduleRule/{pageNum}/{pageSize}/{hoscode}/{depcode}")
    public Result getBookingSchedule(@PathVariable(required = true) int pageNum,@PathVariable(required = true) int pageSize,
                                     @PathVariable(required = true) String hoscode,@PathVariable(required = true) String depcode){
      return Result.ok(scheduleService.getBookingScheduleRule(pageNum,pageSize,hoscode,depcode));
    }



    //获取排班数据详情列表
    @ApiOperation("获取排班数据详情列表")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @PathVariable String hoscode,@PathVariable String depcode,@PathVariable String workDate){
        return Result.ok(scheduleService.getScheduleDetail(hoscode,depcode,workDate));

    }

    //根据排班id获取排班数据
    @ApiOperation("根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
       return Result.ok(scheduleService.getById(scheduleId));
    }

    //根据排班id获取预约下单数据
    @ApiOperation("根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable String scheduleId){
        ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
        return scheduleOrderVo;
    }
}
